package com.together.sfipp.controller;

import com.together.sfipp.pojo.Result;
import com.together.sfipp.pojo.Rules;
import com.together.sfipp.service.RulesService;


import com.together.sfipp.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/rules")
public class RulesController {
    @Resource
    private RulesService rulesService;
    @Autowired
    private UserService userService;

    //增加规则
    @PostMapping("/insert")
    public Result insert(@RequestBody Rules rules) {
        Rules r = rulesService.findByRulesName(rules.getRulesName());
        if (r == null) {
            rulesService.insert(rules);
            return Result.success("添加成功");
        }
        return Result.error("该规则已存在，添加失败");
    }

    //删除规则
    @DeleteMapping("/delete")
    public Result delete(Integer rulesId) {
        rulesService.delete(rulesId);
        return Result.success("删除成功");
    }

    //修改规则
    @PutMapping("/update")
    public Result update(@RequestBody Rules rules) {
        rulesService.update(rules);
        return Result.success("修改成功");
    }

    //查询规则
    @GetMapping("/selectAll")
    public Result selectAll() {
        List<Rules> r = rulesService.selectAll();
        return Result.success(r);
    }
}
